%% Author: John
%% Created: 2010-6-25
%% Description: TODO: Add description to dist_demo
-module(dist_demo).

%%
%% Include files
%%

%%
%% Exported Functions
%% 
%% [How to use]
%% erl -sname mable
%% erl -sname myerlang (in other shell)
%% 
%% then in myerlang ,you can
%% >Pid=dist_demo:start('mable@Your Host').
%% >dist_demo:rpc(Pid,erlang,node,[]).
%%
-export([start/1, rpc/4]).

%%
%% API Functions
%%

%%
%% TODO: Add description of start/function_arity
%%
start(Node) -> 
	spawn(Node,fun()->loop() end).
%%
%% TODO: Add description of rpc/function_arity
%%
rpc(Pid, M, F, A) -> 
	Pid!{rpc,self(),M,F,A},
	receive
		{Pid,Response}->
			Response
	end.

%%
%% Local Functions
%%
loop()->
	receive
		{rpc,Pid,M,F,A}->
			Pid!{self(),(catch apply(M,F,A))},
			loop()
	end.
